package com.zhoug.zmui3demo.ui;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

import com.zhoug.common3.utils.ColorUtils;
import com.zhoug.zmui3.ZMUIShape;
import com.zhoug.zmui3demo.R;

import androidx.appcompat.app.AppCompatActivity;

public class ShapeActivity extends AppCompatActivity {

    private SeekBar mSeekBarWidth;
    private SeekBar mSeekBarColor;
    private Button mBtn1;
    private Button mBtn2;
    private Button mBtn3;
    private Button mBtn4;
    private Button mBtn5;
    private ZMUIShape mShape;
    private TextView mTextColor;
    private Button mBtn6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shape);
        findViews();
        GradientDrawable gradientDrawable=new GradientDrawable();
        gradientDrawable.setColors(new int[]{Color.RED,Color.BLUE});
        gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
        mTextColor.setBackground(gradientDrawable);

        mSeekBarWidth.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mShape.setShapeWidth(progress);
                mShape.postInvalidate();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        mSeekBarColor.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                int color = ColorUtils.blendARGB(Color.RED, Color.BLUE, (1 - progress * 1.0f / mSeekBarColor.getMax()));
                mShape.setShapeColor(color);
                mShape.postInvalidate();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        mBtn1.setOnClickListener(v->{
            mShape.setShape(ZMUIShape.CIRCLE);
            mShape.postInvalidate();
        });
        mBtn2.setOnClickListener(v->{
            mShape.setShape(ZMUIShape.RECT);
            mShape.postInvalidate();
        });
        mBtn3.setOnClickListener(v->{
            mShape.setShape(ZMUIShape.FRAME);
            mShape.postInvalidate();
        });
        mBtn4.setOnClickListener(v->{
            mShape.setShape(ZMUIShape.RING);
            mShape.postInvalidate();
        });
        mBtn5.setOnClickListener(v->{
            mShape.setShape(ZMUIShape.LINE);
            mShape.postInvalidate();
        });
        mBtn5.setOnClickListener(v->{
            mShape.setShape(ZMUIShape.LINE_CIRCLE);
            mShape.postInvalidate();
        });
    }

    private void findViews() {
        mSeekBarWidth = findViewById(R.id.seekBar_width);
        mSeekBarColor = findViewById(R.id.seekBar_color);
        mBtn1 = findViewById(R.id.btn1);
        mBtn2 = findViewById(R.id.btn2);
        mBtn3 = findViewById(R.id.btn3);
        mBtn4 = findViewById(R.id.btn4);
        mBtn5 = findViewById(R.id.btn5);
        mShape = findViewById(R.id.shape);
        mTextColor = findViewById(R.id.text_color);
        mBtn6 = findViewById(R.id.btn6);
    }
}